<script setup>
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app"
import { useStore } from 'vuex'
// import { addPermisionInterceptor } from '@/uni_modules/x-perm-apply-instr/js_sdk/index.js'
import systemApi from '@/api/system'

const store = useStore()

onLaunch(() => {
  console.log('App Launch')

  //App2.6.5+ 仅iOS
  // #ifndef APP-PLUS || H5
  if (uni.canIUse('getUpdateManager')) {
    const updateManager = uni.getUpdateManager()
    updateManager.onCheckForUpdate((res) => {
      if (res.hasUpdate) {
        updateManager.onUpdateReady(() => {
          this.fui.modal('更新提示', '发现新版本，为了获得更好的体验，建议立即更新', (res) => {
            updateManager.applyUpdate()
          })
        })
        updateManager.onUpdateFailed(() => {
          this.fui.modal('更新失败', '新版本更新失败，请稍后再试或删除小程序重新搜索打开',
            (res) => { })
        })
      }
    })
  }
  // #endif

  getRegionList()
})

const getRegionList = () => {
  systemApi.administration().then((res) => {
    if (res.code == 0) {
      const regionData = res.data || []
      store.commit('SET_REGION_DATA', regionData)
    }
  })
}

onShow(() => {
  console.log('App Show')

  // addPermisionInterceptor('chooseImage', '为了提升使用体验，需申请获取相机或存储权限，用于拍摄照片或读取设备上的图片，以便您修改头像。')
})

onHide(() => {
  console.log('App Hide')
})
</script>

<style lang="scss">
@import "./components/firstui/fui-theme/fui-theme.css";
@import "./static/scss/global.scss";
@import "./static/icon/iconfont.css";
</style>